<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button>timeout</button>
</body>
<script>
    const btn = document.querySelector("button");
    btn.onclick = function(){
        btn.innerText = "正在拼命加载中"
        btn.disabled=true;
        const xhr = new XMLHttpRequest();
        xhr.timeout = 3000;// 指定超时的时间
        xhr.open("get","http://zhangpeiyue.com/scoreList");
        xhr.send();
        xhr.onload = function(){
            btn.innerText = "timeout";
            btn.disabled = false;
            console.log(xhr.response);
        }
        xhr.ontimeout = function(){
            alert("请求超时，请稍后再试！");
            btn.innerText = "timeout";
            btn.disabled = false;
        }
    }
</script>
</html>